/*
 * stars_recognition.h
 *
 *  Created on: 17.09.2010
 *      Author: pasha
 */

#ifndef SREC_H_
#define SREC_H_
#include <math.h>
#include <vector>
#include <algorithm>
#include <opencv/cv.h>
#include <list>

using namespace std;

namespace sr
{

const int SECS_IN_DEGREE = 3600;
const int SECS_IN_THE_CITY = 1;
const int SECS_IN_MINUTE = 60;

const double PI = acos(-1);

double sec_to_rad(double sec);
int rad_to_secs(double rad);
int sidsecs_to_secs(int secs);
int DMS_to_secs(int degree, int min, int sec);
int HMS_to_secs(int hour, int min, int sec);

struct Position
{
private:

	Position RA_rotation(Position const & old_position, int new_ra_pos) const;
	Position
	DEC_rotation(Position const & old_position, int new_dec_position) const;

public:

	struct RA
	{
		int deg;
		int min;
		int sec;
		int to_secs() const;

		RA(int secs = 0);
	};

	struct DEC
	{
		int deg;
		int min;
		int sec;
		int sign;

		int to_secs() const;
		DEC(int secs = 0);
	};

	RA ra;
	DEC dec;

	static Position const & get_zero();

	Position get_rotation(Position const & new_center) const;
	Position move_position(int ra, int dec) const;
	int get_ra_shift(Position const & other_pos) const;
	int get_dec_shift(Position const & other_pos) const;
	int distance(Position const & other_pos) const;
	long long sqr_of_distance(Position const & other_pos) const;

	Position();
	Position(int ra_secs, int dec_sec, bool equatorial = true);
	Position(int ra_hour, int ra_min, int ra_sec, int dec_deg, int dec_min,
			int dec_sec, int dec_sign = 1);
};

struct Star: public Position
{

	int HD;
	double magn;
	bool is_marked;
	cv::Scalar color;

	int get_rad(int base, double magn) const;

	Star();
	Star(int ra_deg, int ra_min, int ra_sec, int dec_deg, int dec_min,
			int deg_sec, double magn, int HD, cv::Scalar color =
					CV_RGB(255, 255,
							255), int sign = 1);
	Star(char * entry, std::vector<int> const & marked);
};

class Sphere
{
	vector<vector<list<Star*> > > sphere;

	Star
	* get_nearest_in_deg(Position const & pos, list<Star*> const & degree) const;
public:
	Sphere(vector<Star> & stars);
	Star * get_nearest(Position const &position) const;
	list<Star*> const& get_list(Position const & position) const;
};

vector<Star> find_match(vector<cv::Point2f> const & stars, Sphere const & sky);

}

#endif /* STARS_RECOGNITION_H_ */
